/* ajaxingggg */

// dt ajax object
function DT_PAGE_AJAX() {

    var used_hash = '';
    
    this.do_ajax = function( hash ) {
        hash = hash.slice(1);
        
        if( used_hash == hash ) {
            return false;
        }
        
        used_hash = hash;
        
        var slug = '';
        var page = 1;
        
        if( -1 != hash.search(/\//) ) {
            hash_arr = hash.split('/');
            slug = hash_arr[0];
            page = hash_arr[1];
        }else {
            slug = hash;
        }
        
        // fire ajax
        jQuery.post(
            dt_ajax.ajaxurl,
            {
                // action function
                action : 'dt_ajax_portfolio',
                
                // category slug for filter in query
                dt_slug: slug,

                // page
                dt_page: page,
                
                //ajax url
                dt_ajaxurl: dt_ajax.ajaxurl,
                
                // post id
                dt_post_id: dt_ajax.post_id,
                
                // page_layout
                dt_layout: DT_vars.PageType
            },
            function( response ){
                // insert responce
                $('.cols.benefits').html( $(response.html_content) );
                $('#content .paginator').html( $(response.paginator) );
                
                preloadGallery();
                dt_gal_portf_fade();
                dt_photos_fade( '.col_1-3.highslide' );
                Cufon.refresh();
            }
        );
    }
}

var dt_pajax_obj = new DT_PAGE_AJAX();

function dt_portfolio_ajax() {    
    var holder = $('.filter');
    var hash_orig = '';

    window.onhashchange = function() {
        showBlackLoader();
        dt_pajax_obj.do_ajax( window.location.hash );
    };

    if( !window.location.hash ) {
        window.location.hash = 'all/1';
        window.onhashchange();
    }else {
        window.onhashchange();
    }
        
    hash_orig = window.location.hash.split(/\//);
    hash_orig = hash_orig[0];
    
    holder.find('a').each(function(){
        if( -1 != $(this).attr('href').search(hash_orig) ) {
            holder.find(".act").removeClass("act");
            $(this).addClass("act");
        }
        
        $(this).click(function(){
            
            if( $(this).hasClass('act') ) {
                return false;
            }
            
            // reassign act class properly
            holder.find(".act").removeClass("act");
            $(this).addClass("act");
        });
    });
}// dt_portfolio_ajax end

$(document).ready(function() {
    dt_portfolio_ajax();
});